package com.library.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.library.bean.Admin;
@WebFilter("/*")
public class LoginFilter extends HttpFilter{
	@Override
	protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
			throws IOException, ServletException {
			HttpSession session = request.getSession();
			Admin admin = (Admin)session.getAttribute("loginAdmin");
			String path = request.getRequestURI();
			if(path.contains("login.jsp")||
					path.contains("js/jquery.js")||
					path.contains("login.do")) {
				chain.doFilter(request, response);
				return;
			}
			if(admin!=null) {
				chain.doFilter(request, response);
			}else {
				response.sendRedirect("login.jsp");
			}
	}
}
